<?php

namespace App\Remote\Orm;

use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Validation\ValidationException;
use Symfony\Component\HttpFoundation\Request as RequestAlias;

class InvoiceRemote extends Remote
{
    /**
     * @param array $orders
     * @return mixed
     * @throws GuzzleException
     * @throws ValidationException
     */
    public static function previewInvoice(array $orders)
    {
        return self::customRequestV3(
            "/internal/invoice/previewInvoice?" . http_build_query([
                "new_order_codes" => implode(",", $orders)
            ]),
            RequestAlias::METHOD_GET
        );
    }

    /**
     * 同步订货单id
     *
     * @param array $orders
     * @param int $invoiceId
     * @return mixed
     * @throws GuzzleException
     * @throws ValidationException
     */
    public static function syncOrderInvoiceId(array $orders, int $invoiceId)
    {
        return self::customRequestV3(
            "/internal/invoice/updateInvoiceId",
            RequestAlias::METHOD_POST,
            [
                "new_order_codes" => implode(",", $orders),
                "invoice_id"      => $invoiceId
            ]
        );
    }

    /**
     * 同步订货单状态
     *
     * @param int $invoiceId
     * @param int $status
     * @return mixed
     * @throws GuzzleException
     * @throws ValidationException
     */
    public static function syncOrderInvoiceStatus(int $invoiceId, int $status)
    {
        return self::customRequestV3(
            "/internal/invoice/updateInvoiceStatus",
            RequestAlias::METHOD_POST,
            [
                "invoice_id" => $invoiceId,
                "status"     => $status
            ]
        );
    }
}
